package com.bw.kotlinim.ui.activity

import android.os.Handler
import com.bw.kotlinim.R
import com.bw.kotlinim.base.BaseActivity
import com.bw.kotlinim.contract.splash.SplashContract
import com.bw.kotlinim.contract.splash.SplashPresenter
import org.jetbrains.anko.startActivity

class SplashActivity : BaseActivity(), SplashContract.View {

    private val presenter = SplashPresenter(this)

    override fun init() {
        super.init()
        presenter.checkLoginStatus()//首先检查登录状态，有状态操作
    }

    companion object {
        const val DELAY = 2000L//延时操作
    }

    //懒加载实现  获取实例，形成一个懒汉模式的单例
    private val handler by lazy { Handler() }

    override fun getLayoutId(): Int = R.layout.activity_splash
    //如果没有登录，延时两秒，跳转登录界面
    override fun onNotLoggedIn() {
        handler.postDelayed({
            startActivity<LoginActivity>()//跳转
            finish()
        }, DELAY)
    }
    //已完成登录跳转主页面
    override fun onLoggedIn() {
        startActivity<MainActivity>()
        finish()
    }
}